#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);



}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QDateTime oldtime = ui->dateTimeEdit->dateTime();
    QDateTime newtime = ui->dateTimeEdit_2->dateTime();

    //计算日期差值
    //int days = oldtime.daysTo(newtime);   用daysto函数计算时，如遇到计算某一天和第二天凌晨时，会有错误
    //所以用秒来计算相差日期
    int days = (oldtime.secsTo(newtime)/3600)/24;

    //计算小时差值2
    int hours = (oldtime.secsTo(newtime)/3600)%24;


    QString str = QString::number(days)+"天 零"+QString::number(hours)+"小时";
    ui->label->setText(str);
}
